--群峦
local qunruan = fk.CreateSkill {
    name = "mcdh_qunruan",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

qunruan:addEffect(fk.EventPhaseStart,{
    can_trigger = function (self, event, target, player, data)
        local room = player.room
        local logic = room.logic
        if player:hasSkill(self) and player:usedSkillTimes(self.name,Player.HistoryRound) == 0 and target ~= player and target.phase == Player.Finish  then
            return #logic:getActualDamageEvents(1, function(e)
                if e.data[1].to == player then
                    return true
                end
            end, Player.HistoryRound) == 0
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local logic =  room.logic
        local targets = {}
        logic:getEventsOfScope(GameEvent.Turn, 1, function (e)
            if e.data[1] ~= player and table.contains(room.alive_players,e.data[1]) then
                table.insertIfNeed(targets,e.data[1].id)
            end
            return false
        end, Player.HistoryRound)
        if #targets > 0 then
            local tos = room:askForChoosePlayers(player,targets,1,999,"#mcdh_qunruan-targets",self.name,true)
            targets = table.filter(room:getOtherPlayers(player,true),function(p) return table.contains(tos,p.id)  end)

            player:drawCards(1,self.name)
            for _, p in ipairs(targets) do
                p:drawCards(1,self.name)
            end
        else
            player:drawCards(1,self.name)
        end
    end
})

Fk:loadTranslationTable {
    ["mcdh_qunruan"] = "群峦",
    [":mcdh_qunruan"] = "每轮限一次，其他角色的结束阶段，若你本轮未受到过伤害，你可以与任意名本轮执行过回合的其他角色各摸一张牌。",
    ["#mcdh_qunruan-targets"] = "群峦:选择任意名本轮执行过回合的其他角色,你与他们各摸一张牌。",
}

return qunruan